package cn.iocoder.yudao.module.erp.dal.mysql.dp;

import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.iocoder.yudao.module.erp.controller.admin.dp.dpwsl.vo.DpWslPageReqVO;
import cn.iocoder.yudao.module.erp.dal.dataobject.dp.DpAlmtDO;
import cn.iocoder.yudao.module.erp.dal.dataobject.dp.DpBiskDO;
import cn.iocoder.yudao.module.erp.dal.dataobject.dp.DpWslDO;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.Arrays;
import java.util.List;

/**
 * ERP乌苏里仓库 Mapper
 * @author 天使管理员
 */
@Mapper
public interface DpWslMapper extends BaseMapperX<DpWslDO> {

    default PageResult<DpWslDO> selectPage(DpWslPageReqVO reqVO) {
        return selectPage(reqVO, new LambdaQueryWrapperX<DpWslDO>()
                .likeIfPresent(DpWslDO::getId, reqVO.getId())
                .likeIfPresent(DpWslDO::getNo, reqVO.getNo())
//                .eqIfPresent(DpWslDO::getStoreType, reqVO.getStoreType())
                .likeIfPresent(DpWslDO::getInName, reqVO.getInName())
                .eqIfPresent(DpWslDO::getDispatchNumber, reqVO.getDispatchNumber())
                .eqIfPresent(DpWslDO::getInCount, reqVO.getInCount())
                .eqIfPresent(DpWslDO::getInVolume, reqVO.getInVolume())
                .eqIfPresent(DpWslDO::getWeight, reqVO.getWeight())
                .eqIfPresent(DpWslDO::getRemCount, reqVO.getRemCount())
                .eqIfPresent(DpWslDO::getRemVolume, reqVO.getRemVolume())
                .eqIfPresent(DpWslDO::getRemWeight, reqVO.getRemWeight())
                .eqIfPresent(DpWslDO::getTotalNote, reqVO.getTotalNote())
                .eqIfPresent(DpWslDO::getDensity, reqVO.getDensity())
                .eqIfPresent(DpWslDO::getDeliveryPhone, reqVO.getDeliveryPhone())
                .likeIfPresent(DpWslDO::getDeliveryName, reqVO.getDeliveryName())
                .eqIfPresent(DpWslDO::getEarpayAmount, reqVO.getEarpayAmount())
                .eqIfPresent(DpWslDO::getInPic, reqVO.getInPic())
                .eqIfPresent(DpWslDO::getLine, reqVO.getLine())
                .eqIfPresent(DpWslDO::getWay, reqVO.getWay())
                .eqIfPresent(DpWslDO::getGoodsValue, reqVO.getGoodsValue())
                .eqIfPresent(DpWslDO::getPremium, reqVO.getPremium())
                .eqIfPresent(DpWslDO::getGuaranteedRate, reqVO.getGuaranteedRate())
                .eqIfPresent(DpWslDO::getWriteOff, reqVO.getWriteOff())
                .eqIfPresent(DpWslDO::getWriteExpenses, reqVO.getWriteExpenses())
                .eqIfPresent(DpWslDO::getDiscountAmount, reqVO.getDiscountAmount())
                .eqIfPresent(DpWslDO::getFile, reqVO.getFile())
                .eqIfPresent(DpWslDO::getNote, reqVO.getNote())
                .likeIfPresent(DpWslDO::getShipper, reqVO.getShipper())
                .eqIfPresent(DpWslDO::getDestination, reqVO.getDestination())
                .eqIfPresent(DpWslDO::getConsignee, reqVO.getConsignee())
                .eqIfPresent(DpWslDO::getAdvancePayPack, reqVO.getAdvancePayPack())
                .eqIfPresent(DpWslDO::getAdvancePayPackUp, reqVO.getAdvancePayPackUp())
                .eqIfPresent(DpWslDO::getAdvancePayChinaFreight, reqVO.getAdvancePayChinaFreight())
                .eqIfPresent(DpWslDO::getAdvancePayForGoods, reqVO.getAdvancePayForGoods())
                .eqIfPresent(DpWslDO::getCollecting, reqVO.getCollecting())
                .eqIfPresent(DpWslDO::getCustomerRebate, reqVO.getCustomerRebate())
                .eqIfPresent(DpWslDO::getBusinessRebate, reqVO.getBusinessRebate())
                .eqIfPresent(DpWslDO::getStatus, reqVO.getStatus())
                .eqIfPresent(DpWslDO::getPayType, reqVO.getPayType())
                .eqIfPresent(DpWslDO::getSalesman, reqVO.getSalesman())
                .eqIfPresent(DpWslDO::getUnitPrice, reqVO.getUnitPrice())
                .eqIfPresent(DpWslDO::getCalmethod, reqVO.getCalmethod())
                .eqIfPresent(DpWslDO::getTotalAmount, reqVO.getTotalAmount())
                .eqIfPresent(DpWslDO::getIsSplit, reqVO.getIsSplit())
                .eqIfPresent(DpWslDO::getInventoryStatus, reqVO.getInventoryStatus())
                .eqIfPresent(DpWslDO::getPickStatus, reqVO.getPickStatus())
                .eqIfPresent(DpWslDO::getArrStatus, reqVO.getArrStatus())
                .betweenIfPresent(DpWslDO::getCreateTime, reqVO.getCreateTime())
                .betweenIfPresent(DpWslDO::getChooseDate, reqVO.getChooseDateStr())
                .orderByDesc(DpWslDO::getId));
    }

    default PageResult<DpWslDO> getDpWslPage(DpWslPageReqVO reqVO) {
        return selectPage(reqVO, new LambdaQueryWrapperX<DpWslDO>()
                .likeIfPresent(DpWslDO::getId, reqVO.getId())
                .inIfPresent(DpWslDO::getId,reqVO.getIds())
                .likeIfPresent(DpWslDO::getNo, reqVO.getNo())
                .betweenIfPresent(DpWslDO::getCreateTime, reqVO.getCreateTime())
                .betweenIfPresent(DpWslDO::getChooseDate, reqVO.getChooseDateStr())
                .eqIfPresent(DpWslDO::getCreator, reqVO.getCreator())
                .eqIfPresent(DpWslDO::getStatus, reqVO.getStatus())
                .eqIfPresent(DpWslDO::getLine, reqVO.getLine())
                .likeIfPresent(DpWslDO::getShipper, reqVO.getShipper())
                .likeIfPresent(DpWslDO::getConsignee, reqVO.getConsignee())
                .eqIfPresent(DpWslDO::getPickStatus, reqVO.getPickStatus())
                .eqIfPresent(DpWslDO::getArrStatus, reqVO.getArrStatus())
//                .inIfPresent(DpWslDO::getStatus,0,1)
                //查找 remCount 大于 0 的数据
                .gt(DpWslDO::getRemCount, 0)
                .orderByDesc(DpWslDO::getId));
    }

    default PageResult<DpWslDO> selectRemCountNoZeroPage(DpWslPageReqVO reqVO) {
        return selectPage(reqVO, new LambdaQueryWrapperX<DpWslDO>()
                .likeIfPresent(DpWslDO::getId, reqVO.getId())
                .likeIfPresent(DpWslDO::getNo, reqVO.getNo())
                .eqIfPresent(DpWslDO::getLine, reqVO.getLine())
                .eqIfPresent(DpWslDO::getStatus,1)
                .eqIfPresent(DpWslDO::getPickStatus,0)
                //找出入库状态为0或2的
//                .in(DpWslDO::getInventoryStatus, Arrays.asList(0, 2))
                // 添加条件，查找 remCount 大于 0 的数据
                .gt(DpWslDO::getRemCount, 0)
                .orderByDesc(DpWslDO::getId));
    }

    @Select("<script>" +
            "SELECT temp.id FROM " +
            "(<foreach collection='ids' item='id' separator=' UNION ALL '>" +
            "SELECT #{id} AS id " +
            "</foreach>) temp " +
            "LEFT JOIN erp_dp_wsl ON temp.id = erp_dp_wsl.id " +
            "WHERE erp_dp_wsl.id IS NULL" +
            "</script>")
    List<String> getNotExistIds(@Param("ids") List<String> ids);

}